package com.gis507.mapreduce.splitday;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author leon
 * @ClassName DayDriver.java
 * @createTime 2021年12月12日 16:05:00
 */
public class DayDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //1、新建Job
        Configuration conf = new Configuration();

        conf.set("mapreduce.map.memory.mb","8192");
        conf.set("mapreduce.reduce.memory.mb","8192");

        conf.set("mapred.child.java.opts","-Xmx2048m");

        Job job = Job.getInstance(conf);

        //2、设置jar包
        job.setJarByClass(DayDriver.class);

        //3、关联map和reduce关系
        job.setMapperClass(DayMapper.class);

        //4、设置map的输出类型
        job.setMapOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(Text.class);

        //5、设置最终的输出类型
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Text.class);

        //8、设置分区
        job.setPartitionerClass(DayPartition.class);

        //9、设置分区个数
        job.setNumReduceTasks(15);

        //6、设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path("H:\\Done\\202008\\Tanker.csv"));
        FileOutputFormat.setOutputPath(job,new Path("H:\\DB\\Tanker"));

        //7、提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0:1);
    }
}
